# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=verilator
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.106
pkgrel=2
pkgdesc="The fastest free Verilog HDL simulator (mingw-w64)"
arch=('any')
url="https://www.veripool.org/projects/verilator/wiki/Intro"
license=("LGPL")
groups=("${MINGW_PACKAGE_PREFIX}-eda")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "flex")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")

source=("${_realname}::https://codeload.github.com/${_realname}/${_realname}/tar.gz/v${pkgver}"
        '0002-define-WEXITSTATUS.patch')
sha256sums=('023327b30b68268c6cbf2debf8e8587ea5340b1b0e8b119776a3e7a9e5124140'
            '707b62505f73a6f1d6001cfd0a15a7909285609d3a61fbd9c9e6dbd25e084d9c')

prepare() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  patch -p1 -i "${srcdir}"/0002-define-WEXITSTATUS.patch
  sh autoconf
}

build() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  cp /usr/include/FlexLexer.h src/

  export MSYS2_ARG_CONV_EXCL="-DDEFENV"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
